<template>
  <div style="width: 100%">
    <div>
      <el-input v-model="pagination.title" placeholder="请输入标题" style="width: 200px;" class="filter-item"></el-input>

      <el-button @click="getAll()" class="delfBut">查询</el-button>
      <el-button @click="reload()" class="delfBut">全部</el-button>
    </div>


    <el-table
        v-loading="loading"
        current-row-key="aid"
        :data="dataList"
        style="width: 100%"
    >
      <el-table-column align="center"
                       type="index"
                       label="序号">
      </el-table-column>
      <el-table-column align="center"
                       prop="title"
                       label="标题">
      </el-table-column>


      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="StartAssess(scope.row)">开始测评</el-button>

        </template>
      </el-table-column>


    </el-table>

    <!--分页组件-->
    <div class="pagination-container">

      <el-pagination
          class="pagiantion"

          @current-change="handleCurrentChange"

          :current-page="pagination.currentPage"

          :page-size="pagination.pageSize"

          layout="total, prev, pager, next, jumper"

          :total="pagination.total">

      </el-pagination>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "custom_assess",
  data() {
    return{
      dataList: [],//当前页要展示的列表数据
      pagination: {//分页相关模型数据
        currentPage: 1,//当前页码
        pageSize: 9,//每页显示的记录数
        total: 0,//总记录数
        title: "",
      },
      loading: true,
    }
  },
  created() {
    this.getAll();
  },
  methods:{
    //分页查询
    getAll() {
      // 组织参数，拼接url请求地址
      var paramStr = "?title=" + this.pagination.title;
      axios.get("/assess-service/title/page/" + this.pagination.currentPage + "/" + this.pagination.pageSize + paramStr).then(res => {
        // console.log(res.data);
        this.pagination.currentPage = res.data.data.current;
        this.pagination.pageSize = res.data.data.size;
        this.pagination.total = res.data.data.total;
        this.dataList = res.data.data.records;
        this.loading = false;
      });
    },
    //切换页码
    handleCurrentChange(currentPage) {
      // 修改页码值为当前选中的页码值
      this.pagination.currentPage = currentPage;
      // 执行查询
      this.getAll();
    },
    //重新加载所有内容
    reload() {
      this.pagination.title = '';
      this.getAll();
    },
    StartAssess(row){
      this.$router.push({
            path: "assess_info",
            query:{
              tid: row.tid,
            }
          }
      )
    }
  }
}
</script>

<style scoped>

</style>